package thefirst.mypage.model;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import thefirst.member.model.MemberVO;
@Repository
public class StudentTeacherListDaoImpl implements SelectedListDao {
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	/**
	 * 학생이 찜한 선생님
	 * 선생님을 찜한 학생
	 * SessionScope에 저장된 
	 * (로그인한 회원이)
	 * 학생인지, 선생님인지 구별하여 그에 맞는 메서드를 호출한다. 
	 */
	@Override
	public List<SelectedListVO> showSelectedListVO(MemberVO mvo)
			throws Exception {
		// TODO Auto-generated method stub
		if(mvo.getMembertype().equals("s")){// 학생이 로그인 되어 있으면 
											//if a student is logged, 
			return sqlSessionTemplate.selectList
					("selectedList.showSelectedTeacherListVO",mvo);
					//선택된 선생님의 리스트를 반환한다.
					//Returns a list of selected teachers
		}
		// nor Returns a list of students who select the teacher
		System.out.println("showSelectedListVO : showStudentListVO"+mvo);
		return sqlSessionTemplate.selectList
				("selectedList.showStudentListVO",mvo);
	}

	@Override
	public int countMember_st(MemberVO mvo) throws Exception {
		// TODO Auto-generated method stub
		if(mvo.getMembertype().equals("s")){// 학생이 로그인 되어 있으면 
			return sqlSessionTemplate.selectOne("selectedList.countTeacher_st",mvo);
		}
		System.out.println("countMember_st: "+mvo.getMembertype());
		return sqlSessionTemplate.selectOne("selectedList.countStudent_st",mvo);
	}

	@Override
	public void registerSelectedListVO(SelectedListVO slvo) throws Exception {
		// TODO Auto-generated method stub
		sqlSessionTemplate.insert
		("selectedList.registerSelectedListVOinStudentTeacherList", slvo);
	}
	

	@Override
	public void deleteSelectedListVO(String id) throws Exception {
		 sqlSessionTemplate.delete("selectedList.deleteSelectedTeacher", id);
	}

	@Override
	public List getSelectedList(String id) throws Exception {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.selectList("selectedList.getTeacherList",id);
	}
}
